/**
 * 
 */
package com.thor.palmmall.rest.statement;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.palmmall.api.pay.alipay.MutiChannelAlipayService;
import com.thor.palmmall.api.pay.union.MutiChannelUnionPayService;
import com.thor.palmmall.api.pay.unionmch.MutiChannelUnionMchService;
import com.thor.palmmall.api.pay.wechat.MutiChannelWeChatService;
import com.thor.palmmall.api.pay.wechat.WxPayOrderNotifyResponse;

public class StatementPaymentCallBackServiceImpl implements StatementPaymentCallBackService {

  @Autowired
  MutiChannelAlipayService mutiChannelAlipayService;

  @Autowired
  MutiChannelWeChatService mutiChannelWeChatService;

  @Autowired
  MutiChannelUnionPayService mutiChannelUnionPayService;
  @Autowired
  MutiChannelUnionMchService mutiChannelUnionMchService;

  @Override
  public String alipayCallBack(String request) {
    boolean isSuccess = mutiChannelAlipayService.callBack(request);
    if (isSuccess) {
      return "success";
    } else {
      return "通知失败";
    }
  }

  @Override
  public String weChatCallBack(String request) {
    boolean isSuccess = mutiChannelWeChatService.verifyNotify(request);
    if (isSuccess) {
      return WxPayOrderNotifyResponse.success("SUCCESS");

    } else {
      return WxPayOrderNotifyResponse.success("FAILURE");
    }
  }

  public String unionPayCallBack(String resp) {
    boolean isSuccess = mutiChannelUnionPayService.callBack(resp);
    if (isSuccess) {
      return "ok";
    } else {
      return "通知失败";
    }
  }

  @Override
  public String unionMchCallBack(String response) {
    boolean isSuccess = mutiChannelUnionMchService.callBack(response);
    if (isSuccess) {
      return "ok";
    } else {
      return "通知失败";
    }
  }

}
